<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\model\Admin as AdminModel;
use sand\handle;
use app\admin\controller\Base;
//use think\Loader;
/**
* 
*/
class Admin extends Base
{
    public function index(){
        $admins=model('admin')->paginate(10);
        $this->assign('admins',$admins);
        return $this->fetch();

    }
    public function add(){
        $role = model('role')->select();
        $this->assign('role',$role);
    	return $this->fetch();
    }

    public function doadd(){
    	$validate=validate('Admin');
    	if(!$validate->scene('admin')->check(input('post.')))
    		$this->error($validate->getError()); 
        $user = [
            'uname'=>input('post.uname'),
            'pwd'=>md5(input('post.pwd')),
            'name'=>input('post.name'),
            'rid'=>input('post.rid'),
            'phone'=>input('post.phone')
        ];
        if(!model('admin')->save($user))
            $this->error("管理员添加失败");
        else $this->success("管理员添加成功");   
    }
}